#ifndef _LOCK_H
#define _LOCK_H

#include <unistd.h>
#include <fcntl.h>


int reg_lock(int fd,int cmd,short type,short whence,off_t start,off_t len);

#define read_lock(fd,whence,start,len) reg_lock(fd,F_SETLK,F_RDLCK,whence,start,len)

#define readw_lock(fd,whence,start,len) reg_lock(fd,F_SETLKW,F_RDLCK,whence,start,len)

#define write_lock(fd,whence,start,len) reg_lock(fd,F_SETLK,F_WRLCK,whence,start,len)

#define writew_lock(fd,whence,start,len) reg_lock(fd,F_SETLKW,F_WRLCK,whence,start,len)

#define un_lock(fd,whence,start,len) reg_lock(fd,F_SETLK,F_UNLCK,whence,start,len)


int test_lock(int fd,short type,short whence,off_t start,off_t len);

#define is_read_lockable(fd,whence,start,len) test_lock(fd,F_RDLCK,whence,start,len)
#define is_write_lockable(fd,whence,start,len) test_lock(fd,F_WRLCK,whence,start,len)

void lockfile(char* name);
#endif
